/**
 * Created by hjqi on 2016/6/02.
 */
module.controller('StorageDetailModalController',
  function ($scope, $rootScope, $cookies, $q, $window, $stateParams, $uibModal, $state, storageService, k8sService, VolMgrConf, netTesting, svcCommonService,$mdDialog,radialIndicatorInstance,params) {
      $scope.sName='';
      $scope.createDate='';
      $scope.size=0;
      $scope.remain=0;
      $scope.use=0;
      $scope.appsMount='';
      $scope.percentage={
          radius: 80,
          percentage: true,
          barColor: {
              0: '#11CB77',
              60: '#F9BF3F',
              100: '#FF9191'
          },
          barWidth: 13,
          fontSize: 40,
          roundCorner: true,
          fontWeight: 400,
          initValue: 0
      }

    var get=function () {
       storageService.getStorageDetail(params.ev.name).then(function (data) {
            $scope.sName=params.ev.name;
            $scope.appsMount=params.ev.appsMount;
           $scope.size=(parseFloat(params.ev.size)/1024).toPrecision(2);
           $scope.use=Math.round(parseFloat(data)/parseFloat(params.ev.size)*100);
           $scope.remain=parseInt(params.ev.size)-parseInt(data);
           if($scope.remain>1024){
               $scope.remain=((parseInt(params.ev.size)-parseInt(data))/1024).toPrecision(2)+' GB';
           }else{
               $scope.remain=$scope.remain+' MB';
           }
           if(params.ev.createDate) {
               var d = new Date(params.ev.createDate);
               $scope.createDate = d.getFullYear() + '-' + parseInt(d.getMonth() + 1) + '-' + d.getDate() + " " + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
           }
           // $scope.percentage.initValue=$scope.use;
           // $scope.indicatorValue=$scope.use;
           //$scope.createDate=params.ev.createDate.getFullYear()+'-'+parseInt(params.ev.createDate.getMonth()+1)+'-'+params.ev.createDate.getDate()+" "+params.ev.createDate.getHours()+':'+params.ev.createDate.getMinutes()+':'+params.ev.createDate.getSeconds();
           //$scope.percentage.initValue=$scope.use;
           //$scope.indicatorValue=;
           //$scope.indicatorValue.animate(60);
           radialIndicatorInstance['perId'].animate($scope.use);
       })
    }
    get();
    $scope.used=(params.ev.mountAppNameArray!= undefined&&params.ev.mountAppNameArray.length > 0)?true:false;
      $scope.cancel=function(){
          $mdDialog.cancel();
      };
  }
);